package com.peng.scalatest

;

/**
 * All rights Reserved, Designed By www.rongdasoft.com
 *
 * @version V1.0
 * @Title: ScalaTest_Advance
 * @Description:
 * @author:wsp
 * @date: 2019/10/9
 * @Copyright: 2019/10/9 www.rongdasoft.com
 * Inc. All rights reserved.
 */
object ScalaTest5_Trait {
  def main(args: Array[String]): Unit = {
    var animal = new SuperAnimal
    animal.play("qq")
    animal.talk()
    animal.play3("asd")

  }

  /**
   * trait 相当于java里的接口 ，  带实现的方法相当于java jdk8中的default方法
   */
  trait FlyAnimal {
    def play(s: String): Unit = {
      print("FlyAnimal go~~~~")
    }
  }

  trait SwimAnimal {
    def play2(s: String): Unit = {
      println("SwimAnimal go~~~~")
    }
  }

  trait RunAnimal {
    var a = 3;

    def play3(s: String): Unit = {
      println("RunAnimal go~~~~")
    }
  }

  trait Run2Animal {
    def play3(s: String): Unit = {
      println("RunAnimal2 go~~~~")
    }
  }

  /**
   * 抽象类,  抽象方法不用像java一样再加 abstract关键词
   */
  abstract class AbstractAnimal {

    def talk(): Unit

    def doSomething() = {
      println(123)
    }

  }

  /**
   * 其实 with 相当于 java中的 implements  障眼法
   */
  class SuperAnimal extends AbstractAnimal with FlyAnimal with SwimAnimal with RunAnimal with Run2Animal {

    def talk(): Unit = println("hasagei")

    //多个父类有相同方法时， super调用最后面继承的类的方法
    override def play3(s: String): Unit = super.play3("aaa")
  }


}
